<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Auth extends CI_Controller {

    public $render_data;

    public function __construct() {
        parent::__construct();
        if ($this->uri->segment(1) == 'auth') {
            show_404();
        }
    }

    public function fb_login() {
        
        if ($this->session->userdata('user_id')) 
        {
            redirect('/');
        }
        
        $this->load->library('facebook');
        // Get User ID
        $user_id = $this->facebook->getUser();


        if ($user_id != 0) {

            $this->load->model('user_model', 'user');
            $user_data = $this->facebook->api('/me');
            
            // Login facebook!! //
            if ($user_data) {
                $this->user->fb_login($user_data);
            }
        }
        redirect(base64_decode($this->input->get('redirect')));
    }

    public function login() {
        // For Future Normal Login //
    }

    public function logout() {
        $this->load->model('user_model', 'user');
        $this->user->logout();
        
        redirect(base64_decode($this->input->get('redirect')));
    }

}
